package algorithm.oom;

import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author csp 2023-06-01
 */
public class OOMTest {

    LinkedList<String> list = new LinkedList<>();

    public static void main(String[] args) {
        OOMTest oomTest = new OOMTest();
        ExecutorService service = Executors.newSingleThreadExecutor();
        service.execute(new Runnable() {
            @Override
            public void run() {
                while (true) {
                    String uuid = UUID.randomUUID().toString();
//                    System.out.println("新增数据：" + uuid);
                    oomTest.list.add(uuid);
                }
            }
        });
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                if (!oomTest.list.isEmpty()) {
                    String first = oomTest.list.removeFirst();
//                    System.out.println("删除数据：" + first);
                }
            }
        }, new Date(), 100);

    }

}
